package com.smile.controller;

import cn.hutool.core.bean.BeanUtil;
import com.smile.commons.page.R;
import com.smile.model.dto.request.AddShoppingRequestDTO;
import com.smile.model.request.AddShoppingRequest;
import com.smile.service.ShoppingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/shopping")
public class ShoppingController {

    @Autowired
    private ShoppingService shoppingService;

    @PostMapping("/addShopping")
    public R addShopping(@RequestBody AddShoppingRequest addShoppingRequest) {
        AddShoppingRequestDTO addShoppingRequestDTO = new AddShoppingRequestDTO();
        BeanUtil.copyProperties(addShoppingRequest, addShoppingRequestDTO);
        Boolean result= shoppingService.addShopping(addShoppingRequestDTO);
        if(result){

        return R.ok();
        }else {
            return R.fail();
        }
    }

}
